﻿Imports Microsoft.VisualBasic
Imports Google.GData.Extensions
Imports Google.GData.Client

Public Class NewGoogleCalendarEvent
    Shared Function CreateEvent(ByVal username As String, ByVal password As String, ByVal title As String, ByVal content As String, ByVal minreminders As String, ByVal Location As String, ByVal fromdatetime As String, ByVal todatetime As String) As String
        ' Create a query and service object:
        Dim guid__1 As Guid = Guid.NewGuid()
        Dim query As New FeedQuery()
        query.Uri = New Uri("http://www.google.com/calendar/feeds/" & username & "/private/full")
        'query.Uri = new Uri("https://www.google.com/calendar/feeds/default/private/full");
        Dim minreminder As New Reminder()
        Dim service As New Service("cl", "RonsTestApp")
        'Service service = new Service();
        service.setUserCredentials(username, password)
        Dim calFeed As AtomFeed = service.Query(query)

        Dim entry As New Google.GData.Calendar.EventEntry()
        ' Set the title and content of the entry.
        entry.Title.Text = title
        entry.Content.Content = content & " " & guid__1.ToString()
        'Label2.Text += guid.ToString() + "<br/>";
        minreminder.Minutes = 3
        'minreminder.Minutes = Integer.Parse(minreminders)
        minreminder.Method = Reminder.ReminderMethod.sms
        'minreminder.Method = Reminder.ReminderMethod.email
        'minreminder.Method = Reminder.ReminderMethod.alert

        ' Set a location for the event.
        Dim eventLocation As New Where()
        eventLocation.ValueString = Location
        entry.Locations.Add(eventLocation)

        Dim eventTime As New [When](DateTime.Now.AddMinutes(4), DateTime.Now.AddMinutes(5))
        'When eventTime = new When(DateTime.Now.AddMinutes(20), DateTime.Now.AddMinutes(30));
        entry.Times.Add(eventTime)
        entry.Reminders.Add(minreminder)

        Dim postUri As New Uri("http://www.google.com/calendar/feeds/" & username & "/private/full")
        Dim insertedEntry As AtomEntry = service.Insert(postUri, entry)
        Return guid__1.ToString()


    End Function
End Class
